package com.hefu.virtuallife.ui.purchase;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dz.utlis.ClassTools;
import com.hefu.virtuallife.R;
import com.hefu.virtuallife.baseui.BaseActivity;
import com.hefu.virtuallife.recyclerViewdivider.DecorationMap;
import com.hefu.virtuallife.recyclerViewdivider.RecyclerViewSpacesItemDecoration;
import com.hefu.virtuallife.recyclerViewdivider.ScrollGridLayoutManager;
import com.hefu.virtuallife.ui.purchase.adapter.PersionPointGoodsAdapter;
import com.hefu.virtuallife.ui.purchase.bean.PointGoodsBean;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * creat_user: zhengzaihong
 * email:1096877329@qq.com
 * creat_date: 2018/8/13
 * creat_time: 18:29
 * describe: 个人
 **/
public class PersionInfoActivity extends BaseActivity implements OnRefreshLoadMoreListener {
    @BindView(R.id.iv_back)
    ImageButton ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_right)
    ImageButton ivRight;
    @BindView(R.id.tv_mypoint)
    TextView tvMypoint;
    @BindView(R.id.scrollView)
    ScrollView scrollView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    @BindView(R.id.tv_scan_code)
    TextView tvScanCode;

    private List<PointGoodsBean> listbean;

    private PersionPointGoodsAdapter persionpointgoodsadapter;

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_persion_info;
    }


    @Override
    protected void initWidget() {
        super.initWidget();

        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText("个人");
        ivBack.setOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        super.initData();

        tvMypoint.setOnClickListener(view -> ClassTools.toAct(mContext, MyPointActivity.class));

        refreshLayout.setOnLoadMoreListener(this);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.autoRefresh();
        refreshLayout.setEnableLoadMore(false);

        persionpointgoodsadapter = new PersionPointGoodsAdapter();

        ScrollGridLayoutManager layoutManager = new ScrollGridLayoutManager(mContext, 3);
        layoutManager.setScrollEnable(false);
        recyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(DecorationMap.map(5, 5, 5, 2)));
        recyclerView.setLayoutManager(layoutManager);
        scrollView.smoothScrollTo(0, 0);

        listbean = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            PointGoodsBean bean = new PointGoodsBean();
            listbean.add(bean);
        }
        recyclerView.setAdapter(persionpointgoodsadapter);
        persionpointgoodsadapter.replaceData(listbean);

        tvScanCode.setOnClickListener(view -> ClassTools.toAct(mContext,ScanCodeActivity.class));


       /* RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions
                .request(Manifest.permission.CALL_PHONE)
                .subscribe(granted -> {
                    if (granted) {
                        Toast.makeText(this, "同意权限", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "拒绝权限", Toast.LENGTH_SHORT).show();
                    }
                });
*/
    }

    @Override
    public void onLoadMore(RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {


        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }

}
